//
//  ZCXPetGifTableViewCell.m
//  LoveOfPet
//
//  Created by dllo on 15/11/21.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "ZCXPetGifTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImage+GIF.h>
#import <UIImageView+WebCache.h>
@interface ZCXPetGifTableViewCell ()
@property (nonatomic, retain) UILabel *feelLabel;
@property (nonatomic, retain) UIImageView *gifImageV;
@end

@implementation ZCXPetGifTableViewCell
- (void)dealloc{
    [_imageV release];
    [_feelLabel release];
    [_gif release];
    [super dealloc];
}
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _fun = NO;
        self.feelLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_feelLabel];
        [_feelLabel release];
        
        
        self.imgaeGif = [[UIImageView alloc]init];
        _imgaeGif.userInteractionEnabled = YES;
        [self.contentView addSubview:_imgaeGif];
        [_imgaeGif release];
        
        self.imageV = [[UIImageView alloc]init];
        _imageV.userInteractionEnabled = YES;
        [self.contentView addSubview:_imageV];
        [_imageV release];
        
        self.gifImageV = [[UIImageView alloc]init];
        _gifImageV.image = [UIImage imageNamed:@"Zgif"];
        [self.imageV addSubview:_gifImageV];
        [_gifImageV release];
        
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
     _feelLabel.frame = CGRectMake(5, 5, self.frame.size.width - 10, 50);
    _imageV.frame = CGRectMake(5, 65, self.frame.size.width - 10, self.frame.size.height - 70);
    _imgaeGif.frame = CGRectMake(5, 65, self.frame.size.width - 10, self.frame.size.height - 70);
    _gifImageV.frame = CGRectMake(self.frame.size.width / 2 - 25, self.frame.size.height / 2 - 35, 50, 50);
}
- (void)setGif:(ZCXGifModel *)gif{
    if (_gif != gif) {
        [_gif release];
        _gif = [gif retain];
    }
    [self.delegate sendWithMainPath:gif.mainPicPath];
    
//    [_imgaeGif sd_setImageWithURL:[NSURL URLWithString:self.gif.item.gifPath]];
    [_imageV sd_setImageWithURL:[NSURL URLWithString:gif.mainPicPath]];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pauseOrPlay:)];
    [_imgaeGif addGestureRecognizer:tap];
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pauseOrPlay:)];
    [_imageV addGestureRecognizer:tap1];
    
    _feelLabel.font = [UIFont systemFontOfSize:15];
    _feelLabel.numberOfLines = 0;
    _feelLabel.text = gif.title;
    _feelLabel.textAlignment = NSTextAlignmentCenter;
    _feelLabel.textColor = [UIColor blackColor];
}
- (void)pauseOrPlay:(UIGestureRecognizer *)tap{
    NSLog(@"%d", _fun);
    if (_fun == NO) {
//        _imageV.hidden = YES;
         [_imageV sd_setImageWithURL:[NSURL URLWithString:self.gif.item.gifPath]];
        NSLog(@"dsdfdsd%@", self.gif.item.gifPath);
        _gifImageV.image = nil;
        _fun = YES;
    }else{
        NSLog(@"sdfdsfa");
        _imageV.hidden = NO;
        [_imageV sd_setImageWithURL:[NSURL URLWithString:self.gif.mainPicPath]];
        _gifImageV.image = [UIImage imageNamed:@"Zgif"];
        _fun = NO;
        
    }
 
}
//-(void)sendmainPath:(block)myBlock{
//    self.Block = myBlock;
//}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
